<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>BDMap Sample</title>
    <style type="text/css">
        html {height: 100%;}
        body {height: 100%; margin: 0px; padding: 0px;}
        #container {height: 100%;}
    </style>
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=l6kwGsDiRWk3AP7vvcBGGxaMHQVwIjO6" ></script>
</head>
<body>
    <div id="container"></div>

    <script type="text/javascript">
    window.onload = function() {
        console.log("test");
        var globalLng;
        var globalLat;
        var ovalS = null;
        var Doa = 10;
        var stationMarker = null;
        var mk1;
        var stationIcon = new BMap.Icon("jz16x16.png", new BMap.Size(16,16));

        var map = new BMap.Map("container"); // 创建地图实例
        var point = new BMap.Point(112.960966, 28.334763); // 创建点坐标
        map.centerAndZoom(point, 12); // 初始化地图，设置中心点坐标和地图级别
        map.addControl(new BMap.NavigationControl());
        map.setMapStyle({style:'dark'});
        map.enableScrollWheelZoom(true); // 设置滚轮缩放

        let radian1 = 90;
        let radian2 = 0;
        if (ovalS != null) {
            map.removeOverlay(ovalS);
        }
        ovalS = new BMap.Polygon(sector(new BMap.Point(112.960966, 28.334763), 1000, radian1, radian2), {
            strokeColor: 'red', // 边线颜色
            strokeWeight: 1, // 边线的宽度，以像素为单位
            strokeOpacity: 0.5, // 边线透明度，取值范围0 - 1
            fillColor: 'red', // 填充颜色
            fillOpacity: 0.5 // 透明度
        });
        map.addOverlay(ovalS);

        //qt交互注册
        new QWebChannel(qt.webChannelTransport, function(channel){
            window.JSInterface = channel.objects.JSInterface;
            // 注册逻辑
        });

        // 基站设置
        function myMarker(lng, lat) {
            var newpoint = new BMap.Point(lng, lat);
            if (stationMarker != null) {
                map.removeOverlay(stationMarker);
            }
            stationMarker = new BMap.Marker(newpoint, {
                icon: stationIcon
            });
            map.addOverlay(stationMarker);
        }

        function sector(point, radius, SRadian, ERadian) {
            var points = []; // 创建构成多边形的点数组
            points.push(point); // 起点
            var step = (ERadian - SRadian) / 15 || 15;
            for (var i = SRadian; i < ERadian + 0.001; i += step) {
                points.push(EOffsetBearing(point, radius, i));
            }
            points.push(point);
            return points;
        }

        function EOffsetBearing(point, dist, bearing) {
            var lngConv = map.getDistance(point, new BMap.Point(point.lng + 0.1, point.lat)) * 10;
            var latConv = map.getDistance(point, new BMap.Point(point.lng, point.lat + 0.1)) * 10;
            var lat = (dist * Math.sin((bearing * Math.PI) / 180)) / latConv;
            var lng = (dist * Math.cos((bearing * Math.PI) / 180)) / lngConv;
            return new BMap.Point(point.lng + lng, point.lat + lat);
        }
    };

    </script>
</body>
</html>
